package com.sita.bike.ui.adapter.roadtrust;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sita.bike.R;
import com.sita.bike.persistence.Route;

import java.util.List;

/**
 * @author alessandro.balocco
 */
public class RoadTrustTrackListAdapter extends BaseAdapter {

    private LayoutInflater layoutInflater;
    private List<Route> data;

    public RoadTrustTrackListAdapter(Context context, List<Route> tracks) {
        layoutInflater = LayoutInflater.from(context);
        data = tracks;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        View view = convertView;

        if (view == null) {
            view = layoutInflater.inflate(R.layout.road_trust_track_list_item, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.textView = (TextView) view.findViewById(R.id.road_trust_track_item_text);
            viewHolder.imageView = (ImageView) view.findViewById(R.id.road_trust_track_item_icon);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }

        viewHolder.textView.setText(data.get(position).getDescription());
        viewHolder.imageView.setImageResource(R.drawable.icon);

        return view;
    }

    static class ViewHolder {
        TextView textView;
        ImageView imageView;
    }
}
